#include <iostream>
#include <unistd.h>
#include "message.hpp"
#include "format.hpp"
#include "sink.hpp"

int main()
{
    Log::Formatter formatter;
    Log::LogMessage msg(Log::LogLevel::value::DEBUG, "test.cc", 11, "格式化模块的调试", "日志器1");
    std::string str = formatter.format(msg);
    Log::LogSink::ptr stdout_lsp = Log::SinkFactory::create<Log::StdoutLogSink>();
    Log::LogSink::ptr file_lsp = Log::SinkFactory::create<Log::FileLogSink>("./logfile/test1.log");
    Log::LogSink::ptr rollSize_lsp = Log::SinkFactory::create<Log::RollByFileSizeLogSink>("./logfile/test2.log", 1024 * 1024);
    // Log::LogSink::ptr rollTime_lsp = Log::SinkFactory::create<Log::RollByFileTimeLogSink>("./logfile/test3.log", Log::TimeGap::GAP_SECOND);
    stdout_lsp->Log(str.c_str(), str.size());
    file_lsp->Log(str.c_str(), str.size());
    size_t cursize = 0;
    size_t count = 0;
    while(cursize < 1024*1024*10)
    {
        std::string tmp = str + std::to_string(count++);
        rollSize_lsp->Log(tmp.c_str(), tmp.size());
        // rollTime_lsp->Log(tmp.c_str(), tmp.size());
        cursize += tmp.size();
        usleep(100);
    }

    return 0;
}